<%--
  Created by IntelliJ IDEA.
  User: lenovo
  Date: 2024/5/20
  Time: 18:52
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>学生管理页面</title>
</head>
<body>
<div class="container">
    <!--顶部-->
    <jsp:include page="top.jsp"/>

    <!--主体界面-->
    <div class="row">
        <section class="col-sm-4 offset-sm-4">
            <form id="form">
                <div class="form-group">
                    <label>用户名：</label>
                    <input type="text" name="loginName" class="form-control"/>
                </div>

                <div class="form-group">
                    <label>密码：</label>
                    <input type="password" name="secretCode" class="form-control"/>
                </div>

                <div class="form-group">
                    <label>管理员登录：</label>
                    <div class="form-check form-check-inline">
                        <input type="radio" name="loginType" class="form-check-input" id="admin" value="admin"/>
                        <label class="form-check-label" for="admin">管理员</label>
                    </div>
                </div>


                <div class="form-group">
                    <label>学生登录：</label>
                    <div class="form-check form-check-inline">
                        <input type="radio" name="loginType" class="form-check-input" value="studentNo" id="studentNo"/>
                        <label class="form-check-label" for="studentNo">学号</label>
                    </div>

                    <div class="form-check form-check-inline">
                        <input type="radio" name="loginType" class="form-check-input" value="studentPhone" id="studentPhone"/>
                        <label class="form-check-label" for="studentPhone">手机</label>
                    </div>

                    <div class="form-check form-check-inline">
                        <input type="radio" name="loginType" class="form-check-input" value="studentEmail" id="studentEmail"/>
                        <label class="form-check-label" for="studentEmail">邮箱</label>
                    </div>
                </div>

                <div class="form-group">
                    <input type="button" id="trueLoginBtn" class="btn btn-primary btn-block" value="登录"/>

                </div>
            </form>
        </section>
    </div>

    <!--底部-->
    <jsp:include page="bottom.jsp"/>
</div>

<script>
    $("#trueLoginBtn").on("click",function () {
        $.ajax({
            type:'post',
            url:'<%=request.getContextPath()%>/login',
            contentType:'application/json',
            //因为传递过去的是键值对，所以使用封装函数，封装起来
            data:JSON.stringify(formDataObj("form")),
            success:function (result) {
                if(result.success){
                    //如果是管理员，就跳转到管理员登录页面
                    //获取单选框的值,对于input标签：$(":属性")
                    var loginTypeChecked = $(":radio:checked").val()
                    if("admin" === loginTypeChecked){
                        location.href = "<%=request.getContextPath()%>/admin/toStudentManage";
                    }else{
                        //跳转到学生信息页面
                        location.href = "<%=request.getContextPath()%>/student/toUpdate?id="+result.data;
                    }
                }else{
                    $("#tipCont").text(result.errMsg)
                    $("#tioModal").modal("show")
                }
            }
        })
    })
</script>
</body>
</html>